// web/src/app/api/(social)/channels/route.ts
import {NextRequest, NextResponse} from "next/server";
import {db} from "@/lib/db";

export async function GET(req: NextRequest) {
    const searchParams = req.nextUrl.searchParams;
    let workspaceId = (searchParams.get('workspaceId'))

    let where = {}
    // @ts-ignore
    if (workspaceId) where.workspaceId = workspaceId
    const channels = await db.channel.findMany({
        where
    })

    return NextResponse.json(channels)
}

export async function POST(req: NextRequest) {
    try {
        const data = await req.json()
        const channel = await db.channel.create({
            data
        })
        return NextResponse.json({channel})
    } catch (err) {
        console.error(err)
        return NextResponse.json({err})
    }
}